package com.scqkxx.gamebox.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.android.tu.loadingdialog.LoadingDailog;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.myself.LoginActivity;
import com.scqkxx.gamebox.activity.myself.MyselfEditNicknameActivity;

public class DialogUtils {


    private static Dialog dialog;

    public static void  showDialog(Context context){
        LoadingDailog.Builder loadBuilder=new LoadingDailog.Builder(context)
                .setMessage("加载中...")
                .setCancelable(true)
                .setCancelOutside(true);
        dialog=loadBuilder.create();
        dialog.show();
    }

    public static void dismiss(){
        if (dialog  != null) dialog.dismiss();
    }


    /**
     * 底部得dialog
     * @param context
     * @param view
     * @return
     */
    public static Dialog showBottonDialog(Context context ,View view){
        Dialog dialog = new Dialog(context ,R.style.Theme_Design_BottomSheetDialog);
        dialog.setContentView(view);
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setGravity( Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 20;
        lp.width = LinearLayout.LayoutParams.MATCH_PARENT;
        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        return dialog;
    }


    /**
     * 底部得dialog
     * @param context
     * @param view
     * @return
     */
    public static Dialog showCenterDialog(Context context ,View view){
        Dialog dialog = new Dialog(context ,R.style.Theme_Design_BottomSheetDialog);
        dialog.setContentView(view);
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setGravity( Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 20;
        lp.width = LinearLayout.LayoutParams.MATCH_PARENT;
        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        return dialog;
    }
}
